package com.yoomiito.app.widget.dialog;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.yoomiito.app.R;

public class ApkDownloadDialog extends BaseDialog implements View.OnClickListener{

    private ProgressBar mProgressBar;
    private TextView mSizeTv;
    private String size;
    private TextView installTv;
    private boolean click = false;
    private OnClickListener1 mOnClickListener;
    public ApkDownloadDialog(@NonNull Context context) {
        this(context,0);
    }

    public ApkDownloadDialog(@NonNull Context context, int themeResId) {
        super(context, R.style.dialog_2);
    }

    protected ApkDownloadDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    @Override
    public View setView() {
        View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_apk_download,null,false);
        installTv = view.findViewById(R.id.dialog_net_tip_btn);
        installTv.setOnClickListener(this);
        installTv.setEnabled(click);
        mProgressBar = view.findViewById(R.id.dialog_net_tip_progressbar);
        mSizeTv = view.findViewById(R.id.dialog_net_tip_size);
        mSizeTv.setText(size);
        mProgressBar.setProgress(0);
        setCanceledOnTouchOutside(false);
        return view;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.dialog_net_tip_btn:
                if (mOnClickListener!=null)mOnClickListener.onClick();
                break;
        }
    }

    @Override
    public void onBackPressed() {

    }

    public void setProgress(int progress){
        if (mProgressBar!=null){
            mProgressBar.setProgress(progress);
        }
    }

    public void setClick(boolean click) {
        this.click = click;
        if (installTv!=null){
            installTv.setEnabled(click);}
    }

    public void setSize(String size){
        this.size = size;
        if (mSizeTv!=null){
            mSizeTv.setText(size);
        }
    }

    public void setOnClickListener(OnClickListener1 onClickListener) {
        mOnClickListener = onClickListener;
    }

    public interface OnClickListener1{
        void onClick();
    }
}
